﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace MangaRipper.Core
{
    class TitleMangaGo:TitleBase
    {
        public TitleMangaGo(Uri address) : base(address) { }
        static Regex _htmlRegex = new Regex("<.*?>", RegexOptions.Compiled);

        protected override List<IChapter> ParseChapterObjects(string html)
        {
            var list = new List<IChapter>();
            Regex reg = new Regex(@"[^]<h4>[$]<a target=""_self"" class=""chico"" href=""(?<Value>[^<]+)"">(?<Text>[^<]+[<b>][^<]+)",
                RegexOptions.Multiline);
            MatchCollection matches = reg.Matches(html);

            foreach (Match match in matches)
            {
                if(match.Groups["Text"].Value.Contains("<b>")){
                    var value = new Uri(Address, match.Groups["Value"].Value);
                    string name = _htmlRegex.Replace(match.Groups["Text"].Value.Trim(), string.Empty);
                    IChapter chapter = new ChapterMangaGo(name, value);
                    list.Add(chapter);
                }
            }

            return list.Distinct().ToList();
        }
    }
}
